
import { _decorator, Component, instantiate, Node, PageView, Size, size, Terrain, Vec3 } from 'cc';
import { DataHelper } from '../system/DataHelper';
import { SecondGunListItem } from './SecondGunListItem';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = SecondGunList
 * DateTime = Sun Jun 11 2023 10:30:00 GMT+0800 (GMT+08:00)
 * Author = guoxun
 * FileBasename = SecondGunList.ts
 * FileBasenameNoExtension = SecondGunList
 * URL = db://assets/script/pop/SecondGunList.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

@ccclass('SecondGunList')
export class SecondGunList extends Component {
    @property(PageView)
    mPVGunView: PageView = null;
    @property(Node)
    mNdItem: Node = null;
    @property(Node)
    mContent: Node = null;
    private mConfigList = [];
    private mLtPageNodes = [];
    private mCurIndex = 0;

    protected onLoad(): void {
        this.node.getChildByName("mask").on(Node.EventType.TOUCH_END, () => {
            this.node.destroy();
        });
        this.InitView();
    }

    InitView() {
        let config = DataHelper.GetSpecialSkillConfig();
        for (const key in config) {
            if (Object.prototype.hasOwnProperty.call(config, key)) {
                const element = config[key];
                this.mConfigList.push(element);
            }
        }
        for (let i = 0; i < this.mConfigList.length; i++) {
            const pageNode = instantiate(this.mNdItem);
            pageNode.active = true;
            pageNode.getComponent(SecondGunListItem).InitData(this.mConfigList[i]);
            this.mContent.addChild(pageNode)
        }
        this.mPVGunView.getComponent(PageView).scrollToPage(0);
        this.mCurIndex = 0;

        this.mPVGunView.getComponent(PageView)
    }

    // OnPageEvent(event: PageView) {
    //     let direction = event.getCurrentPageIndex() - this.mCurIndex;
    //     this.mCurIndex = event.getCurrentPageIndex();
    //     if (event.getCurrentPageIndex() == event.getPages().length - 1 && direction == 1) {
    //         let node = instantiate(event.getPages()[0]);
    //         if (!this.mConfigList[this.mCurIndex + 1]) return;
    //         node.getComponent(SecondGunListItem).InitData(this.mConfigList[this.mCurIndex + 1]);
    //         event.addPage(node);
    //     }
    // }

    // 绑定滑动事件

    start() {
        // [3]
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
